home *** CD-ROM | disk | FTP | other *** search
/ Die Ultimative Software-P…i Collection 1996 & 1997 / Die Ultimative Software-Pakete CD-ROM fur Atari Collection 1996 & 1997.iso / i / internet / software / netstsr / cookie.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-20  |  1.8 KB  |  79 lines

  1. #include <stdlib.h>
  2. #include <tos.h>
  3. #include "cookie.h"
  4. #include <stdio.h>
  5. #ifndef NULL
  6. #define NULL (void *)0L
  7. #endif
  8. #define _cookiejar    *(long *)0x5A0L
  9.  
  10.  
  11. COOKIE *new_cookiejar(long n)
  12. {
  13.   register long superstack;
  14.   register COOKIE *jar,*newjar;
  15.   register long i,c;
  16.  
  17.   jar = get_cookiejar();
  18.   i=0;
  19.   if(jar) for(; jar[i].id != ENDCOOKIE; i++);  /* get size of old jar */
  20.   if(jar && jar[i].val > n) return(jar);  /* there isroom in jar */
  21.  
  22.   newjar = (COOKIE *)malloc(n*sizeof(COOKIE));/* alloc new jar */
  23.   if(jar && newjar) for(c=0; c<i; c++)
  24.   {  /* copy old jar */
  25.     newjar[c].id = jar[c].id;
  26.     newjar[c].val = jar[c].val;
  27.   }
  28.   newjar[i].id = ENDCOOKIE;  /* terminate new jar */
  29.   newjar[i].val = n;
  30.   superstack = Super((void *)0);
  31.   _cookiejar = (long)newjar;  /* install new jar */
  32.   Super((void*)superstack);
  33.   return(newjar);
  34. }
  35.  
  36. COOKIE *get_cookiejar(void)
  37. {
  38.   register long superstack;
  39.   register long cookieaddress;
  40.   
  41.   if(Super((void*)1L))
  42.   {
  43.     cookieaddress = _cookiejar;  /* return address of cookiejar */
  44.   }
  45.   else
  46.   {
  47.     superstack = Super(0L);
  48.     cookieaddress = _cookiejar;  /* return address of cookiejar */
  49.     Super((void*)superstack);
  50.   }
  51.     return (COOKIE *)cookieaddress;
  52. }
  53.  
  54. COOKIE *add_cookie(long id,long val)
  55. {
  56.   register COOKIE *jar;
  57.   if((jar = new_cookiejar(8L))==NULL) return(NULL);
  58.   while(jar->id != ENDCOOKIE) jar++;  /* search end of cookiejar */
  59.   jar->id = id;
  60.   (jar+1)->val = jar->val;  /* keep size of jar */
  61.   jar->val = val;
  62.   (jar+1)->id = ENDCOOKIE;
  63.   return(jar);
  64. }
  65.  
  66.  
  67. COOKIE *get_cookie(long id)
  68. {
  69.   register COOKIE *jar;
  70.   if((jar = get_cookiejar()) == NULL) return(NULL);
  71.   while(jar->id)
  72.   {
  73.     if(jar->id == id) return(jar);  /* find cookie */
  74.     jar++;
  75.   }
  76.   return(NULL);
  77. }
  78.  
  79.